<template>
  <div>
    <workflowEditPanel
      ref="workflowEditPanel"
      :nodeData="nodeData"
      @update="update"
    ></workflowEditPanel>
    <updateForm ref="updateForm"></updateForm>
  </div>
</template>

<script>
import updateForm from "./updateForm";
import workflowEditPanel from "@/components/Workflow/panel";
export default {
  components: { workflowEditPanel, updateForm },
  data() {
    return {
      nodeData: {},
      data: {}
    };
  },
  mounted() {
    debugger;
    this.loadData(this.$route.query.versionId, this.$route.query.id);
  },
  methods: {
    loadData(versionid, id) {
      let _this = this;
      this.$store
        .dispatch("workflow/getWorkflowVersion", { versionid, id })
        .then(res => {
          _this.nodeData =
            res.drawingInfo.length == 0
              ? this.defaultNode()
              : JSON.parse(res.drawingInfo);
          _this.data = res;
          _this.$refs.workflowEditPanel.loadNodeData();
        });
    },
    defaultNode() {
      return {
        name: "",
        nodeList: [],
        lineList: []
      };
    },
    update(data) {
      debugger;
      var form = {
        des: this.data.description,
        name: this.$route.query.name,
        versionDescription: ""
      };

      for (var key in data) {
        form[key] = data[key];
      }
      form.workflowId = {
        versionId: this.data.versionNo,
        id: this.data.workflowId
      };
      this.$refs.updateForm.show(form);
    }
  }
};
</script>

<style></style>
